package com.mrduan.calculator.utils;

import java.text.DecimalFormat;

/**
 * Created by snoopy on 2018/3/15.
 */

public class Common {

    /**
     * 格式化 数字显示
     *
     * @param string
     * @return
     */
    public static String stringFormat(String string) {

        String strings[] = string.split("\\.");

        String format = string;

        if (strings.length > 0) {
            long data = Long.valueOf(strings[0]);

            DecimalFormat df = new DecimalFormat("#,###");
            format = df.format(data);
        }

        if (string.indexOf(".")  != -1) {
            format += ".";
        }

        if (strings.length > 1) {
            format += strings[1];
        }

        return format;
    }

}
